package multithreading;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

//callable的call比runnable可以带返回值，并且可以抛出异常
public class ThirdThread {
    public static void main(String[] args)
{
        //先用future包装callable
        ThirdThread rt=new ThirdThread();
        FutureTask<Integer>task=new FutureTask<Integer>((Callable<Integer>)()->{
        int i=0;
        for(;i<100;i++){
        System.out.println(Thread.currentThread().getName()+"循环变量i值： "+i);

        }
        return i;
        });
        for(int i=0;i<100;i++){
        System.out.println(Thread.currentThread().getName()+" "+i);
        if(i==20){
        new Thread(task,"1").start();
        }
        }
        try {
        System.out.println("返回值"+task.get());
        } catch(Exception ex)
        {
        ex.printStackTrace();}
        }
}

